/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.drone.recorder.video;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import ch.randelshofer.media.quicktime.QuickTimeOutputStream;
import ch.randelshofer.media.quicktime.QuickTimeOutputStream.VideoFormat;
import fr.uha.ensisa.jmp.drone.app.DroneConstants;
import fr.uha.ensisa.jmp.drone.recorder.FileWriter;

public class MovWriter extends FileWriter<BufferedImage>
{
	private QuickTimeOutputStream os;
	private VideoFormat encodingFormat;
	
	public MovWriter(VideoFormat encodingFormat)
	{
		this.encodingFormat = encodingFormat;
	}
	
	@Override
	public void open() throws IOException
	{
		File file = new File(this.path + "." + "mov");
		this.os = new QuickTimeOutputStream(file, encodingFormat);
		this.os.setTimeScale(DroneConstants.VIDEO_FRAMERATE); 

	}

	@Override
	public void close() throws IOException
	{
		this.os.close();
	}

	@Override
	public void write(BufferedImage record) throws IOException
	{
		this.os.writeFrame(record, 1);
	}

}
